<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script type="module">

        async function test() {
            //await 同步代码/promise对象
            try {
                let author = "kerwin"
                const res = await fetch(`http://localhost:3000/news?author=${author}`).then(res => res.json())
                console.log(res);

                const res1 = await fetch(`http://localhost:3000/comments?newsId=${res[0].id}`)
                const res2 = await res1.json()
                console.log(res1);
                console.log(res2);
                return res2
            } catch (err) {
                console.log("error", err);
            }
        }

        // console.log(test()); //返回的是一个promise对象
        test().then(() => {
            console.log("666");
        })

    </script>
</body>

</html>